<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/

// Joomla security
defined('_JEXEC') or die;
 
## Import Joomla Data
jimport('joomla.application.component.controlleradmin');
 
## Text string controller
class JoosamControllerTextstrings extends JControllerAdmin{
	protected $text_prefix = 'Textstrings';

	## Delete Button
	public function delete(){
		$jspost = JRequest::getVar('cid');
		$sqlid = $jspost[0];
		$allow = $this->sqlgetinfo($sqlid);
		$code = $this->sqlgetcode($sqlid);
		if ($allow == 'true'){
			$this->setMessage(JText::_('COM_JOOSAM_TXTSTRING_DELETE_DEFAULT_ERROR'), 'warning');
			$this->setRedirect(JRoute::_('index.php?option=com_joosam&view=textstrings', false));
		
		}
		else if ($allow == 'false'){
			$this->sqldelrow($sqlid);
			$this->setMessage(JText::_('COM_JOOSAM_TXTSTRING_DELETE_DONE'));
			$this->setRedirect(JRoute::_('index.php?option=com_joosam&view=textstrings', false));
		}
		else{
			$this->setMessage(JText::_('COM_JOOSAM_NO_CODE_MOD_ALLOWED'), 'warning');
			$this->setRedirect(JRoute::_('index.php?option=com_joosam&view=textstrings', false));
		}
	}

	## Get Sam Errorcode
	protected function sqlgetcode($sqlid){
		$db =& JFactory::getDBO();
		$query = "
			SELECT ".$db->nameQuote('samerror')."
			FROM ".$db->nameQuote('#__joosam_txt')."
			WHERE ".$db->nameQuote('id')." = ".$db->quote($sqlid).";
		";
		$db->setQuery($query);
		$result = $db->loadResult();
		return $result;
	}

	## Get sql info about string
	protected function sqlgetinfo($sqlid){
		$db =& JFactory::getDBO();
		$query = "
			SELECT ".$db->nameQuote('isdef')."
			FROM ".$db->nameQuote('#__joosam_txt')."
			WHERE ".$db->nameQuote('id')." = ".$db->quote($sqlid).";
		";
		$db->setQuery($query);
		$result = $db->loadResult();
		return $result;
	}

	## Delete row
	protected function sqldelrow($sqlid){
		$db =& JFactory::getDBO();
		$query = "
			DELETE
			FROM ".$db->nameQuote('#__joosam_txt')."
			WHERE ".$db->nameQuote('id')." = ".$db->quote($sqlid).";
		";
		$db->setQuery($query);
		$db->query();
		return true;
	}

	## Model
	public function &getModel($name = 'Textstring', $prefix = 'JoosamModel'){
		$model = parent::getModel($name, $prefix, array('ignore_request' => true));
		return $model;
	}
}
?>